-
Notifications
You must be signed in to change notification settings - Fork 262
Support push for Live Activity #668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
hi bro when the feature can be used? Thanks! package main
import (
"context"
firebase "firebase.google.com/go/v4"
"firebase.google.com/go/v4/messaging"
"fmt"
"google.golang.org/api/option"
"log"
"os"
"time"
)
func main() {
println(os.Getwd())
// 使用下载的服务账户密钥文件路径
opt := option.WithCredentialsFile("./mePlus/to_firebase_ios/serviceAccountKey.json")
app, err := firebase.NewApp(context.Background(), nil, opt)
if err != nil {
log.Fatalf("error initializing app: %v\n", err)
}
ctx := context.Background()
client, err := app.Messaging(ctx)
if err != nil {
log.Fatalf("error getting Messaging client: %v\n", err)
}
now := time.Now()
unixTime := time.Unix(1546304, 0)
fcmOptions := new(messaging.APNSFCMOptions)
fcmOptions.AnalyticsLabel = "test-live-activity"
message := &messaging.Message{
APNS: &messaging.APNSConfig{
Headers: map[string]string{
"apns-priority": "10",
//"apns-topic": "", // 必须添加的实时活动主题头
"apns-push-type": "liveactivity", // 标识为实时活动推送
},
Payload: &messaging.APNSPayload{
Aps: &messaging.Aps{
Alert: &messaging.ApsAlert{
Title: "123",
Body: "123",
},
//Sound: "default",
StaleDate: &unixTime,
Event: messaging.LiveActivityEventStart,
Attributes: map[string]interface{}{},
AttributesType: "MissedEnergy",
ContentState: map[string]interface{}{},
DismissalDate: &unixTime,
Timestamp: &now,
},
},
FCMOptions: fcmOptions,
LiveActivityToken: "80a8a14077cc0e4392fbb5f4ae7bb329dbf0af5b8b384c5d1baba0a78b3227be3dbeba200dbfa150b8705f9364b0f5204d92267d82c093315911f9c9ed35be76a0c004c140c340d18644b2b7a513fd09",
},
Token: "dJ1H2SMWU0Q4lC6TI6_lED:APA91bGStzxLSXcpbPtwE_S8PcfOZt6Ob-BMAetQaenKa0WRtA6G731E1kAhzIjH4NvZsE1_37KYZmv-hBNWWg_F02Bwpc1rKopBhti1cOw_dGer8WHOLfg",
}
// 发送消息
response, err := client.Send(ctx, message)
if err != nil {
log.Fatalf("error sending message: %v\n", err)
}
// 打印响应
fmt.Printf("成功发送消息: %s\n", response)
} |
HI Guys, |
@lahirumaramba Hi, I have a request regarding for code review of this 👀 The Please, code review if possible would be greatly appreciated 🙋🏼 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @morikuni, Thanks for getting started on this. Could you remove the extra fields added and limit to just LiveActivityToken field. Thanks!
StaleDate *time.Time `json:"-"` | ||
ContentState map[string]interface{} `json:"content-state,omitempty"` | ||
Timestamp *time.Time `json:"-"` | ||
Event LiveActivityEvent `json:"-"` | ||
DismissalDate *time.Time `json:"-"` | ||
AttributesType string `json:"attributes-type,omitempty"` | ||
Attributes map[string]interface{} `json:"attributes,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the extra fields from this PR and focus on adding just the LiveActivityToken field. These live activity payload fields should be possible to add using the existing Aps.CustomData
field.
Added keys for Live Activity push.
Firebase Document: https://firebase.google.com/docs/cloud-messaging/ios/live-activity
Firebase API Reference: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#apnsconfig
APNS Reference: https://developer.apple.com/documentation/usernotifications/generating-a-remote-notification